<template>
	<u-form :model="form" ref="uForm">
		<u-form-item label="姓名"><u-input v-model="form.name" /></u-form-item>
		<u-form-item label="手机号"><u-input v-model="form.phone" /></u-form-item>
		<u-form-item label="性别">
			<u-radio-group v-model="form.sex">
				<u-radio v-for="(item, index) in sexList" :key="index" :name="item.name" :disabled="item.disabled">
					{{ item.name }}
				</u-radio>
			</u-radio-group>
		</u-form-item>
		<u-form-item label="邮箱"><u-input v-model="form.email" /></u-form-item>
		<u-form-item label="身份证"><u-input v-model="form.idcard" /></u-form-item>
		<u-form-item label="生日">
			<u-calendar v-model="show" :mode="mode" @change="change"></u-calendar>
			<u-button @click="show = true">请选择</u-button>
		</u-form-item>
		<u-form-item label="公开"><u-switch slot="right" v-model="form.isChat"></u-switch></u-form-item>
		<button @click="update">确认</button>
	</u-form>
</template>

<script>
export default {
	data() {
		return {
			form: {
				studentId:'',
				name: '',
				sex: '',
				phone:'',
				email:'',
				idcard:'',
				birthday:'',
				isChat:'',
			},
			show: false,
			mode: 'date',
			sexList:[
				{
					name:'男',
					disabled: false
				},
				{
					name:'女',
					disabled: false
				}
			]
		};
	},
	methods:{
		open(){
			this.$refs.calendar.open();
		},
		onShow(){
			this.list()
		},
		list(){
			this.$u.api.findStuById().then(res => {
				this.form = res.data
				// 信息是否公开
				this.switchVal = res.data.isChat
			}
			)
		},
		update(){
			// 发送更新信息的请求
			this.$u.api.updateStudent(this.form).then(res => {
				//弹出
				let str = res.msg;
				uni.showToast({
				   title: str,
				   icon: "primary",
				   success: () => {
					
				   }
				 });
			}
			)
		},
		// 日期更改器拿到日期放在生日里
		change(e){
			// 格式转化会异常
			this.form.birthday = e.result;
		}
	}
};
</script>